package com.qf.micropoint.point.service.impl;

import com.qf.common.core.entity.PointRule;
import com.qf.common.redis.utils.RedisKeyConstant;
import com.qf.common.redis.utils.RedisUtils;
import com.qf.micropoint.point.mapper.PointRuleMapper;
import com.qf.micropoint.point.service.IPointRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * --- 天道酬勤 ---
 *
 * @author QiuShiju
 * @date 2025/11/10
 * @desc
 */
@Service
public class PointRuleServiceImpl implements IPointRuleService {

    @Autowired
    private PointRuleMapper pointRuleMapper;

    @Autowired
    private RedisUtils redisUtils;

    @Override
    public List<PointRule> ruleList() {
        // 从redis中获取积分规则
        List<PointRule> ruleListCache = redisUtils.getCacheObject(RedisKeyConstant.POINT_KEY);

        // 如果没有规则,查询,放进去
        if (Objects.isNull(ruleListCache)) {
            List<PointRule> ruleList = pointRuleMapper.selectList(null);
            redisUtils.setCacheObject(RedisKeyConstant.POINT_KEY,ruleList);
        }
        return ruleListCache;
    }
}
